package com.example.lin.generate.mybatis;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.query.SQLQuery;

import java.util.Collections;

/**
 * @className: CodeGenerator
 * @description: 代码生成器
 * @author: Lin.Gu
 * @date: 2025-11-21  15:36
 */
public class CodeGenerator {
    //https://baomidou.com/reference/new-code-generator-configuration/
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://10.238.238.130:3306/efn_metric?useUnicode=true&characterEncoding=UTF-8",
                        "dev_admin",
                        "dev_admin@2021")
                .globalConfig(builder -> {
                    builder.author("gulin") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .outputDir("D://test"); // 指定输出目录
                })
                .dataSourceConfig(builder ->
                        builder.databaseQueryClass(SQLQuery.class)
                                .typeConvert(new MySqlTypeConvert())
                                .dbQuery(new MySqlQuery())
                )
                .packageConfig(builder ->
                        builder.parent("com.itiaoling.efn.metric") // 设置父包名
                                .moduleName("web") // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.xml, "D://test")) // 设置mapperXml生成路径
                )
                .strategyConfig(builder ->
                        builder.addInclude("t_metric_stock") // 设置需要生成的表名
                                .addTablePrefix("t_", "c_") // 设置过滤表前缀
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
